#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QResizeEvent>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //先把QLabel设置成和窗口一样大
    //让QLabel铺满整个窗口
    QRect rect = this->geometry();
    ui->label->setGeometry(0, 0, rect.width(), rect.height());

    QPixmap pixmap(":/doge.png");
    ui->label->setPixmap(pixmap);
    //开启自动拉伸
    ui->label->setScaledContents(true);

}

Widget::~Widget()
{
    delete ui;
}

//这里形参的event包含了触发这个 resize 事件这一时刻, 窗口的尺寸的数值
void Widget::resizeEvent(QResizeEvent *event)
{
    qDebug() << event->size();
    ui->label->setGeometry(0, 0, event->size().width(), event->size().height());

}
